package com.vercon.moensmart.newtork.interceptor;

import android.util.Log;

import androidx.annotation.NonNull;

import com.vercon.common.Constants;
import com.vercon.common.utils.MirrorDataStorage;
import com.vercon.moensmart.BuildConfig;
import com.vercon.moensmart.newtork.mode.SignMode;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class HeaderInterceptor implements Interceptor {




    @NonNull
    @Override
    public Response intercept(@NonNull Chain chain) throws IOException {
        SignMode signMode;
        if(BuildConfig.DEBUG){
            //测试服
            signMode = new SignMode("c2ec4d80bfa711eca21324418c29779a","c2ec4d81bfa711ecbe9524418c29779a",
                    "HD5dpzDXEerpY7FDADXan3WGyWtKteed",String.valueOf(System.currentTimeMillis() / 1000));
        }else {
            //正式服
            signMode = new SignMode("","","","");
        }
        Request.Builder builder = chain.request()
                .newBuilder()
                .header("Authorization", "token "+ MirrorDataStorage.instance().getString(Constants.STORAGE_KEY_TOKEN,""))
                .addHeader("appid", signMode.appid)
                .addHeader("appSerect", signMode.appSerect)
                .addHeader("nonce", signMode.nonce)
                .addHeader("ts", signMode.ts)
                .addHeader("sign", signMode.getSign());
        Log.d("","HeaderInterceptor " + signMode);
        return chain.proceed(builder.build());
    }

}
